package com.xyh.concurrency.example.immutable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.xyh.concurrency.annoations.ThreadSafe;
import lombok.extern.slf4j.Slf4j;

/**
 * 下面展示的是不可变对象
 * <dependency>
 * <groupId>com.google.guava</groupId>
 * <artifactId>guava</artifactId>
 * <version>25.1-jre</version>
 * </dependency>
 * guava   java框架中封装的不可变对象
 */
@Slf4j
@ThreadSafe
public class ImmutableExample2 {
    private final static ImmutableList list = ImmutableList.of(1, 2, 3);
    private final static ImmutableSet set = ImmutableSet.copyOf(list);
    private final static ImmutableMap map = ImmutableMap.of(1, 2, 3, 4);
    private final static ImmutableMap map2 = ImmutableMap.builder().put(1, 2).put(3, 4).build();

    public static void main(String[] args) {
        //不能进行修改就会报错
        list.add(4);
        //
        set.add(2);
        map.get(1);
        map2.put(1, 3);

    }

}
